/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.ux.select;

import java.util.ArrayList;
import java.util.List;

import org.rails.extjs.Option;
import org.rails.extjs.form.Field;

public class ItemSelector extends Field {
	
	private List<MultiSelect> multiselects = new ArrayList<MultiSelect>();
	
	public ItemSelector() {
		super();
	}

	public ItemSelector(Option configOptions) {
		super(configOptions);
	}

	public ItemSelector(String name) {
		super(name);
	}

	public ItemSelector(String name, String fieldLabel) {
		super(name, fieldLabel);
	}

	public ItemSelector(String name, String fieldLabel, Object value) {
		super(name, fieldLabel, value);
	}
	
	@Override
	public void createItems(){
		super.createItems();
		if(multiselects.size() > 0)
			addOption("multiselects", multiselects);
	}
	
	public void setHideNavIcons(Boolean hideNavIcons){
		addOption("hideNavIcons",hideNavIcons);
	}
	
	public Boolean isHideNavIcons(){
		return getBoolean("hideNavIcons",false);
	}
	
	public void setImagePath(String imagePath){
		addOption("imagePath",imagePath);
	}
	
	public String getImagePath(){
		return getString("imagePath","");
	}
	
	public void setIconUp(String iconUp){
		addOption("iconUp",iconUp);
	}
	
	public String getIconUp(){
		return getString("iconUp","up2.gif");
	}
	
	public void setIconDown(String iconDown){
		addOption("iconDown",iconDown);
	}
	
	public String getIconDown(){
		return getString("iconDown","down2.gif");
	}
	
	public void setIconLeft(String iconLeft){
		addOption("iconLeft",iconLeft);
	}
	
	public String getIconLeft(){
		return getString("iconLeft","left2.gif");
	}
	
	public void setIconRight(String iconRight){
		addOption("iconRight",iconRight);
	}
	
	public String getIconRight(){
		return getString("iconRight","");
	}
	
	public void setIconTop(String iconTop){
		addOption("iconTop",iconTop);
	}
	
	public String getIconTop(){
		return getString("iconTop","top2.gif");
	}
	
	public void setIconBottom(String iconBottom){
		addOption("iconBottom", iconBottom);
	}
	
	public String getIconBottom(){
		return getString("iconBottom","bottom2.gif");
	}
	
	public void setDrawUpIcon(Boolean drawUpIcon){
		addOption("drawUpIcon", drawUpIcon);
	}
	
	public Boolean isDrawUpIcon(){
		return getBoolean("drawUpIcon",true);
	}
	
	public void setDrawDownIcon(Boolean drawDownIcon){
		addOption("drawDownIcon", drawDownIcon);
	}
	
	public Boolean isDrawDownIcon(){
		return getBoolean("drawDownIcon",true);
	}
	
	public void setDrawLeftIcon(Boolean drawLeftIcon){
		addOption("drawLeftIcon", drawLeftIcon);
	}
	
	public Boolean isDrawLeftIcon(){
		return getBoolean("drawLeftIcon", true);
	}
	
	public void setDrawRightIcon(Boolean drawRightIcon){
		addOption("drawRightIcon", drawRightIcon);
	}
	
	public Boolean isDrawRightIcon(){
		return getBoolean("drawRightIcon", true);
	}
	
	public void setDrawTopIcon(Boolean drawTopIcon){
		addOption("drawTopIcon", drawTopIcon);
	}

	public Boolean isDrawTopIcon(){
		return getBoolean("drawTopIcon",true);
	}
	
	public void setDrawBotIcon(Boolean drawBotIcon){
		addOption("drawBotIcon", drawBotIcon);
	}
	
	public Boolean isDrawBotIcon(){
		return getBoolean("drawBotIcon",true);
	}
	
	public void setDelimiter(String delimiter){
		addOption("delimiter", delimiter);
	}
	
	public String getDelimiter(){
		return getString("delimiter", ",");
	}
	
	public void setBodyStyle(String bodyStyle){
		addOption("bodyStyle", bodyStyle);
	}
	
	public String getBodyStyle(){
		return getString("bodyStyle","");
	}
	
	public void setBorder(Boolean border){
		addOption("border", border);
	}
	
	public Boolean isBorder(){
		return getBoolean("border",false);
	}
	
	public void setMultiselects(MultiSelect available,MultiSelect selected){
		multiselects.add(available);
		multiselects.add(selected);
	}
	
	public MultiSelect getAvailable(){
		return multiselects.get(0);
	}
	
	public MultiSelect getSelected(){
		return multiselects.get(1);
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		addOption("xtype","itemselector");
		script.append(createOptions());
		return script.toString();
	}

}
